<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教务班级列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>班级名：</label>
                            <input type="text" name="className"/>
                        </li>
                        <li>
                            <label>上课时间：</label>
                            <input type="text" class="time-input" placeholder="请选择上课时间" name="teachTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="teaching:classes:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="teaching:classes:edit">-->
            <!--                    <i class="fa fa-edit"></i> 修改-->
            <!--                </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="teaching:classes:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="teaching:classes:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('teaching:classes:edit')}]];
    var removeFlag = [[${@permission.hasPermi('teaching:classes:remove')}]];
    var prefix = ctx + "teaching/classes";
    var class_status = [[${@dict.getType('sys_classes_status')}]];
    var delFrag = 0;

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "班级",
            queryParams: {
                delFrag: delFrag,
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'classId',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'className',
                    title: '班级名',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.classId + '\')">' + value + '</a>';
                    }
                },
                {
                    // field: 'maxStudent',
                    title: '人数',
                    formatter: function (value, row, index) {
                        return row.classStudent + '/' + row.maxStudent;
                    }
                },
                {
                    field: 'teacherName',
                    title: '上课老师'
                },
                {
                    field: 'courseName',
                    title: '课程'
                },
                {
                    field: 'teachingSchool.name',
                    title: '所属校区'
                },
                // {
                //     field: 'classStudent',
                //     title: '在读人数'
                // },

                // {
                //     field: 'classroomName',
                //     title: '教室'
                // },
                {
                    field: 'status',
                    title: '招生状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(class_status, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='detail(" + row.classId + ")'><i class='fa fa-check-square-o'></i>分配学员</a>");
                        more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='$.operate.edit(" + row.classId + ")'><i class='fa fa-edit'></i>编辑</a>");
                        more.push("<a class='btn btn-default btn-xs' href='javascript:void(0)' onclick='endClass(" + row.classId + ")'><i class='fa fa-address-book'></i>结班</a>");
                        more.push("<a class='btn btn-default btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.classId + ")'><i class='fa fa-remove'></i>删除班级</a> ");
                        var moreMenu = more.join('');
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + moreMenu + '"><i class="fa fa-chevron-circle-down"></i>操作</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*班级-详细*/
    function detail(classId) {
        var url = prefix + '/info/' + classId;
        $.modal.openTab("班级详情", url);
    }

    function endClass(classId) {
        var url = prefix + '/endClass';
        $.modal.confirm("确定要结班吗？", function () {
            var data = {"classId": classId};
            $.operate.post(url, data, function (result) {
                if (result.code == 0) {
                    $.modal.alertSuccess("结班成功！");
                }
            })
        })

    }
</script>
</body>
</html>
